﻿using System;
using Sinacor.Infra.UI.Common;
using Sinacor.Infra.UI.Security.Services;
using Sinacor.UI.Bovespa.Parametro.Communication.Bovespa.Parametro.Parametro;

namespace Sinacor.UI.Bovespa.Parametro.Communication
{
    public class Parametro : BaseCommunication
    {
        #region Construtor
        public Parametro(SessionInformation session)
            : base(session)
        {

        }
        #endregion

        #region  Método

        //Task : 5435
        //Data :02/03/3009
        //Autor: Andre
        /// <summary>
        /// Retornar os parametros da tabela de parametro Bovespa
        /// </summary>
        /// <returns></returns>
        public Sinacor.UI.Bovespa.Parametro.Model.Parametro ObterParametro()
        {
            IParametro servico = null;
            Sinacor.UI.Bovespa.Parametro.Model.Parametro response = null;

            try
            {
                using (ServiceInstance<IParametro> service = new ServiceInstance<IParametro>())
                {
                    servico = service.TryGetInstance(this.Session);
                    response = (new Communication.Translator.DataContractToModel.Parametro().ToParametro(servico.ObterParametro()));
                }
            }
            catch (Exception ex)
            {
                base.HandleFault(ex);
            }
            return response;
        }

        //Task : 5435
        //Data :02/03/3009
        //Autor: Andre
        /// <summary>
        /// Atualizar os parametros a partir da model
        /// </summary>
        /// <param name="model"></param>
        public void AlterarParametro(Sinacor.UI.Bovespa.Parametro.Model.Parametro model)
        {
            IParametro servico = null;

            try
            {
                using (ServiceInstance<IParametro> service = new ServiceInstance<IParametro>())
                {
                    servico = service.TryGetInstance(this.Session);
                    servico.AlterarParametro(new Communication.Translator.ModelToDataContract.parametro().ToParametro(model));
                }
            }
            catch (Exception ex)
            {
                base.HandleFault(ex);
            }

        }

        #endregion
    }
}
